<template>
  <div class="app-container">
    <uc-table url="admin/equipment/getInEquipmentMonitorVoPage" name="监控" ref="InEquipmentMonitorTable" pageable table-border :search-form="searchForm">
      <template slot="searchForm">
        <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
          <!--搜索输入框-->
          <el-form-item>
            <el-select v-model="searchForm.buildId" placeholder="请选择建筑" style="width: 100%" clearable @clear="clearInput1()">
              <el-option v-for="(item,index) in equipmentList" :key="index"  :value="item.ucId" :label="item.disPlayName"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-if="enterPriseHidden">
            <el-select v-model="searchForm.enterpriseId" placeholder="请选择企业" clearable @clear="clearInput2()">
              <el-option v-for="(item,index) in enterpriseDominantList"  :key="index" :value="item.ucId" :label="item.name"></el-option>
            </el-select>
          </el-form-item>
          <!--搜索按钮--新增按钮-->
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" class="filter-item" @click="handleSearch()">查询</el-button>
            <el-button type="success" icon="el-icon-plus" class="filter-item" @click="handleAdd()">新 增</el-button>
          </el-form-item>
        </el-form>
      </template>
      <template slot="columns">
        <el-table-column prop="buildName" label="建筑名称" align="left" show-overflow-tooltip></el-table-column>
        <el-table-column prop="enterpriseName" label="企业名称" align="left" show-overflow-tooltip ></el-table-column>
        <el-table-column prop="address" label="地址" align="left" show-overflow-tooltip ></el-table-column>
        <el-table-column prop="serialId" label="序列号" align="left" show-overflow-tooltip ></el-table-column>
        <el-table-column prop="LANIP" label="公共ip" align="left" show-overflow-tooltip ></el-table-column>
        <el-table-column prop="PNIP" label="载体" align="left" show-overflow-tooltip ></el-table-column>
        <el-table-column prop="port" label="端口" align="left" show-overflow-tooltip ></el-table-column>
        <el-table-column prop="address" label="操作" width="220" align="left" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <!--编辑按钮-->
            <el-button size="mini" icon="el-icon-edit" type="primary" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button size="mini" type="danger" icon="el-icon-delete" :loading="deleteLoading" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </template>
    </uc-table>
  </div>
</template>

<script>
import UcTable from "@/components/UcTable/index.vue";
import {getEquipmentList} from "@/api/equipment";
import {getInEnterpriseDominantList} from "@/api/enterpriseDominant";
import {deleteInEquipmentMonitor} from "@/api/inEquipmentMonitor";
import {getBuildingList} from "@/api/building";

export default {
  name: "list",
  components: {UcTable},
  data(){
    return{
      searchForm:{
        deleted:false,
        equipmentList:this.$route.query.equipmentList

      },
      deleteLoading:false,
      equipmentList:[],
      enterpriseDominantList:[],        }
  },
  created() {
    this.getEquipmentList()
    this.getInEnterpriseDominantList()
  },
  computed:{
    enterPriseHidden(){
      let roleCode = this.$store.getters.roleCode;
      return roleCode=="ADMIN"||roleCode=="XT-ADMIN"||roleCode=="ZD-ADMIN"||roleCode=="DD-ADMIN"||roleCode=="JW-ADMIN"
    }
  },
  methods:{
    handleSearch(){
      this.$refs.InEquipmentMonitorTable.getTableData(1)
    },
    handleAdd(){
      this.$router.push("/equipment/inEquipmentMonitorEdit/0")
    },
    handleEdit(val){
      this.$router.push("/equipment/inEquipmentMonitorEdit/"+val.ucId)
    },
    clearInput1(){
      //清除输入框
      this.searchForm.equipmentList = null

      this.handleSearch()
    },
    clearInput2(){
      //清除输入框
      this.enterpriseDominantList = null
      this.handleSearch()
    },
    handleDelete(val){
      this.$confirm('您确定要执行删除这条监控信息吗？', '提醒信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteLoading = true
        deleteInEquipmentMonitor(val).then(res=>{
          this.deleteLoading = false
          this.$notify.success({
            title: '成功',
            message: "删除监控信息成功"
          })
          this.handleSearch()
        }).catch(res=>{
          this.deleteLoading = false
          this.$notify.error({
            title: '失败',
            message: res.msg
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    getEquipmentList(){
      getBuildingList({deleted:false}).then(res=>{
        this.equipmentList = res.data
      }).catch(error=>{

      })
    },
    getInEnterpriseDominantList(){
      getInEnterpriseDominantList({deleted:false}).then(res=>{
        this.enterpriseDominantList = res.data
      }).catch(error=>{

      })
    }


  }
}
</script>

<style scoped>

</style>